package com.bwhx.eruler.controller;

import java.util.HashMap;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.commons.CommonsMultipartFile;

import com.bwhx.eruler.util.Constant;
import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.WebResource;



@Controller
public class EBARLogFileController extends BaseController {
	
	
	@ResponseBody
	@RequestMapping(value = "/ebar.uploadlog.ashx",method=RequestMethod.POST)
	public HashMap<String,String> uploadPic(@RequestParam(value = "myfiles", required = false) CommonsMultipartFile file,HttpServletRequest request ){
		
		HashMap<String,String> resultMap = new HashMap<String,String>();
		byte[] bfile = file.getBytes();
		
		String orgFileName = file.getOriginalFilename();
		
/*		String suffix = orgFileName.substring(orgFileName.lastIndexOf("."));
*/		//第一步创建jersey的客户端
		Client client = Client.create();
		//指定文件在服务器上全路径
		WebResource webResource =  client.resource(Constant.EBARLOGFILE_FULLPATH+orgFileName);
		webResource.put(String.class, bfile);

		resultMap.put("status", "1");
		resultMap.put("msg", "上传成功");
		resultMap.put("full_path", Constant.EBARLOGFILE_FULLPATH+orgFileName);
		resultMap.put("relative_path", Constant.EBARLOGFILE_RELATIVEPATH+orgFileName);
		
		return resultMap;
		
	}
	
	

}
